package com.example.dazuoye.service.impl;
import com.example.dazuoye.mapper.UserMapper;
import com.example.dazuoye.model.Car;
import com.example.dazuoye.model.Order;
import com.example.dazuoye.model.User;
import com.example.dazuoye.model.Wallet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.example.dazuoye.service.UserService;

import java.util.Date;
import java.util.List;

@Service
public class UserServiceimpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    public Car getcarinfo(int c_id)
    {
        Car car;
        car = userMapper.getcarinfo(c_id);
        return car;
    }
    public Wallet getwalletinfo(String u_id) {
        Wallet wallet;
        wallet=userMapper.getwalletinfo(u_id);
        return wallet;
    }
    public Date getvipinfo(String u_id)
    {
        return userMapper.getvipinfo(u_id);
    }
    public User getuserinfo(String u_id)
    {
        User user;
        user=userMapper.getuserinfo(u_id);
        return user;
    }

    @Override
    public void insertlicensepic(String u_id, String picurl) {
        userMapper.uplicensepic(u_id);
        userMapper.licensepic(u_id,picurl);
    }

    public void insertuser(String u_id, int accepted, int money, int deposit, int coupon_count)
    {
        userMapper.newuseritem(u_id,accepted);
        userMapper.newvipitem(u_id);
        userMapper.newwalletitem(u_id,money,deposit,coupon_count);
    }

    public void setviptime(String u_id, Date endtime) {
        userMapper.setviptime(u_id,endtime);
    }

    public void charge(String u_id, int amount) {
        userMapper.charge(u_id,amount);
    }

    public void pd(String u_id, int amount) {
        userMapper.paydeposit(u_id,amount);
    }

    public void costmoney(String u_id, int cost) {
        userMapper.costmoney(u_id,cost);
    }

    public List<Car> getallcar() {
        return userMapper.getallcar();
    }

    public List<Car> getunusedcar(){return  userMapper.getunusedcar();}
    @Override
    public String getcarsite(int c_id) {
        return userMapper.getcarinfo(c_id).getCarsite();
    }

    @Override
    public void setcarsite(int c_id, String carsite) {
        userMapper.updatecarsite(c_id,carsite);
    }

    public int getusingstate(int c_id)
    {
        return userMapper.getusingstate(c_id);
    }


    public void setusingstate(int c_id, int isusing)
    {
        userMapper.updateusingstate(c_id, isusing);
    }

    @Override
    public void starttime(String u_id, int c_id, Date start) {
        userMapper.insertstarttime(u_id,c_id,start);
    }

    @Override
    public void finish(String u_id, int c_id, Date finish, String payoff) {
        userMapper.updatefinishtime(u_id,c_id,finish,payoff);
    }

    @Override
    public Date searchstarttime(String u_id, int c_id) {
        return userMapper.searchstarttime(u_id,c_id);
    }

    @Override
    public List<Order> getorder(String u_id) {
        List<Order> t=userMapper.getorder(u_id);
        for (Order o:t)
        {
            //System.out.println(o.getTips());
            o.settips();
            //System.out.println(o.getTips());
        }
        return t;
    }

    @Override
    public List<Order> getfinishorder(String u_id) {
        List<Order> t=userMapper.getfinishorder(u_id);
        for (Order o:t)
        {
            //System.out.println(o.getTips());
            o.settips();
            //System.out.println(o.getTips());
        }
        return t;
    }
    @Override
    public List<Order> getunfinishorder(String u_id) {
        List<Order> t=userMapper.getunfinishorder(u_id);
        for (Order o:t)
        {
            //System.out.println(o.getTips());
            o.settips();
            //System.out.println(o.getTips());
        }
        return t;
    }
}
